#pragma once
#include <iostream>
#include <vector>
namespace bit
{
    class bitset
    {
    public:
        bitset(size_t N)
        {
            _bits.resize(N / 32 + 1, 0);
            _num = 0;
        }
        void set(size_t x)
        {
            size_t index = x / 32;
            size_t pos = x % 32;
            _bits[index] |= (1 << pos);
            ++_num;
        }
        void reset(size_t x)
        {
            size_t index = x / 32;
            size_t pos = x % 32;
            _bits[index] &= (~(1 << pos));
            --_num;
        }
        bool test(size_t x)
        {
            size_t index = x / 32;
            size_t pos = x % 32;
            return _bits[index] & (1 << pos);
        }
        const size_t size() const
        {
            return _num;
        }

    private:
        std::vector<int> _bits;
        size_t _num;
    };
    void test()
    {
        bitset bs(100);
        std::cout << bs.size() << std::endl;
        bs.set(99);
        bs.set(98);
        bs.set(96);
        bs.set(92);
        std::cout << bs.size() << std::endl;
        bs.reset(99);
        std::cout << bs.size() << std::endl;
        for (int i = 0; i < 100; i++)
        {
            printf(" [%d] : %d\n", i, bs.test(i));
        }
    }
}